ENGLISH:

How to create or convert a stable/pasture into an expandable stable/pasture

The mod FS22_SimpleExpandablePastures from me can be used as an example for this. This is also available in the ModHub.

First of all you need to add a Dependency for Expandable pastures in the modDesc file of your mod like:

<dependencies>
	<dependency>FS22_ExpandablePastures</dependency>
</dependencies>

Then you have to create the stable/pasture like a normal stable/pasture mod. You can only omit the generation of the NavMesh.

Now you have to perform the following steps:

- The type of the stable/pasture must be adapted (you can find this in the xml of the stable/pasture in the first line where the placeable begins). For this you can take the type from the following table.

	Standard Type -> Expandable Pasture Type

	cowHusbandry -> FS22_ExpandablePastures.expandableCowHusbandry
	cowHusbandryFeedingRobot -> FS22_ExpandablePastures.expandableCowHusbandryFeedingRobot
	cowHusbandryPasture -> FS22_ExpandablePastures.expandableCowHusbandryPasture
	pigHusbandry -> FS22_ExpandablePastures.expandablePigHusbandry
	pigHusbandryPasture -> FS22_ExpandablePastures.expandablePigHusbandryPasture
	sheepHusbandry -> FS22_ExpandablePastures.expandableSheepHusbandry
	chickenHusbandry -> FS22_ExpandablePastures.expandableChickenHusbandry
	horseHusbandry -> FS22_ExpandablePastures.expandableHorseHusbandry
	horseHusbandryPasture -> FS22_ExpandablePastures.expandableHorseHusbandryPasture
	
- Now you must enter the plane (This must be ONE shape), which is actually used to calculate the NavMesh in the Giants Editor, in the xml of the stable/pasture (the plane must be used here and not the generated NavMesh!). The plane must have the Build Nav Mesh Mask "fe". This plane must be entered under placeable.husbandry.animals.navigation as navMeshPlaneNode. The filename parameter is no longer required. The line should look something like this:

<navigation rootNode="navigationRootNode" navMeshPlaneNode="navMeshPlaneNode"/>

Now the stable/pasture is expandable Pasture ready.

Optional steps:
As the Animal Grazing Mod uses the Foliage Area to calculate the pasture, but this results in the grass in the Foliage Area being replaced. This is not always desirable on existing pastures. I have therefore created a way to define the animal grazing area without replacing the foliage. To do this, you can define animalGrazingAreas that are structured in exactly the same way as the foliage areas (these can therefore be replaced one-to-one). This can be entered in the xml as follows:


    <animalGrazingAreas>
        <animalGrazingArea startNode="animalGrazingArea1Start" widthNode="animalGrazingArea1Width" heightNode="animalGrazingArea1Height"/>
    </animalGrazingAreas>
	

If you want to create your own stable types, this is also possible. All you have to do is add the FS22_ExpandablePastures.placeableHusbandryAnimalsExtension as a specialization. It should then look like this, for example:

<placeableTypes>
    <type name="cowHusbandryManure" parent="baseHusbandry" filename="$dataS/scripts/vehicles/Vehicle.lua">
    	<specialization name="husbandryWater" />
        <specialization name="husbandryMilk" />
        <specialization name="husbandryStraw" />
        <specialization name="husbandryLiquidManure" />
        <specialization name="manureHeap" />
        <specialization name="FS22_ExpandablePastures.placeableHusbandryAnimalsExtension" />
    </type>
</placeableTypes>


If you have buildings or maps that are loaded before Expandable Pastures, the following two scripts are required. These can be entered in the ModDesc. For example (Thanks to [EAM] GlengarBoy for the scripts):

<extraSourceFiles>
	<sourceFile filename="scripts/expandablePastures_register.lua"/>
</extraSourceFiles>

<type name="cowHusbandryManure" parent="cowHusbandry" filename="$dataS/scripts/placeables/Placeable.lua">
            <specialization name="manureHeap" />
            <specialization name="expandablePasturesRegistry"/>
</type>

File expandablePastures_register.lua:

>>>
expandablePastures_register = {};

local modName = g_currentModName

-- add specializations to placeableTypes
function expandablePastures_register:register(name)

	-- make sure this only runs once since typeManager runce twice (vehicle and placeables)
    if expandablePastures_register.installed == nil then

		-- add/register specializations

		-- cycle placeableTypes, add specs
		local specCount = 0;
        for _, placeable in pairs(g_placeableTypeManager:getTypes()) do

			local placeableHusbandryExtension = false
			local expandablePasturesRegistry = false
			for _, spec in pairs(placeable.specializationNames) do
				if spec == "FS22_ExpandablePastures.placeableHusbandryAnimalsExtension" then
					placeableHusbandryExtension = true;
				end
				if spec == modName..".expandablePasturesRegistry" then
					expandablePasturesRegistry = true;
				end;
			end
			if not placeableHusbandryExtension and expandablePasturesRegistry then
				g_placeableTypeManager:addSpecialization(placeable.name, "FS22_ExpandablePastures.placeableHusbandryAnimalsExtension")
                specCount = specCount + 1;
			end

			expandablePastures_register.installed = true
		end
        print("Info: Successfully added FS22_ExpandablePastures.placeableHusbandryAnimalsExtension specialization to "..specCount .." placeableTypes in "..modName)
	end
end
TypeManager.finalizeTypes = Utils.prependedFunction(TypeManager.finalizeTypes, expandablePastures_register.register)

addModEventListener(expandablePastures_register)
<<<


File ExpandablePasturesRegistry.lua:

>>>
ExpandablePasturesRegistry = {}

function ExpandablePasturesRegistry.prerequisitesPresent(specializations)
    return true
end
<<<



	
DEUTSCH:


Wie erstelle oder konvertiere einen Stall/Weide in eine erweiterbare/n Stall/Weide

Als Beispiel hierfür kann der Mod FS22_SimpleExpandablePastures von mir herangezogen werden. Dieser ist ebenfalls im ModHub verfügbar.

Als Erstes muss eine Abhängigkeit in die modDesc Datei der Mod eingetragen werden. Dies sieht wie folgt aus:

<dependencies>
	<dependency>FS22_ExpandablePastures</dependency>
</dependencies>

Dann musst du den Stall/Weide wie einen ganz normalen Stall/Weide Mod erstellen. Nur das generieren der NavMesh kannst du weglassen.

Nun musst du folgende Schritte durchführen:

- Der type des Stalls/Weide muss angepasst werden (Diesen findest du in der xml des Stalls/Weide in der ersten Zeile, wo das placeable beginnt). Hierfür kannst du den Type aus folgender Tabelle nehmen.

	Standard Type -> Expandable Pasture Type

	cowHusbandry -> FS22_ExpandablePastures.expandableCowHusbandry
	cowHusbandryFeedingRobot -> FS22_ExpandablePastures.expandableCowHusbandryFeedingRobot
	cowHusbandryPasture -> FS22_ExpandablePastures.expandableCowHusbandryPasture
	pigHusbandry -> FS22_ExpandablePastures.expandablePigHusbandry
	pigHusbandryPasture -> FS22_ExpandablePastures.expandablePigHusbandryPasture
	sheepHusbandry -> FS22_ExpandablePastures.expandableSheepHusbandry
	chickenHusbandry -> FS22_ExpandablePastures.expandableChickenHusbandry
	horseHusbandry -> FS22_ExpandablePastures.expandableHorseHusbandry
	horseHusbandryPasture -> FS22_ExpandablePastures.expandableHorseHusbandryPasture
	
- Nun musst du die Plane (Diese muss zwingend EINE Shape sein), welche eigentlich zur Berechnung der NavMesh im Giants Editor verwendet wird, in der xml des Stalls/Weide eintragen (Hier muss die Plane genommen werden und nicht die generierte NavMesh!). Die Plane muss zwingend die Build Nav Mesh Mask "fe" haben. Diese Plane muss unter placeable.husbandry.animals.navigation als navMeshPlaneNode eingetragen sein. Der parameter filename wird nicht mehr benötigt. Die Zeile sollte in etwa so aussehen:

<navigation rootNode="navigationRootNode" navMeshPlaneNode="navMeshPlaneNode"/>

Nun ist der Stall/Weide expandable Pasture ready.

Optinale Schritte:
Da der Animal Grazing Mod die Foliage Area zum berechnen der Weide heranzieht, was jedoch dazu führt, dass das Gras im Bereich der Foliage Area ausgetauscht wird. Dies ist auf bereits vorhandenen Weiden nicht immer gewünscht. Daher habe ich einen Weg geschaffen, die Animal Grazing Area zu definieren, ohne die Foliage auszutauschen. Hierfür kann man animalGrazingAreas definieren, die genau so aufgebaut sind wie die Foliage Areas (Diese können somit eins zu eins ausgetauscht werden). Dies kann man wie folgt in die xml eintragen:


    <animalGrazingAreas>
        <animalGrazingArea startNode="animalGrazingArea1Start" widthNode="animalGrazingArea1Width" heightNode="animalGrazingArea1Height"/>
    </animalGrazingAreas>


Falls man eigene Stall typen erstellen möchte, ist dies ebenfalls möglich. Hierzu muss man nur die FS22_ExpandablePastures.placeableHusbandryAnimalsExtension als Spezialisierung hinzufügen. Sollte dann beispielsweise so aussehen:

<placeableTypes>
    <type name="cowHusbandryManure" parent="baseHusbandry" filename="$dataS/scripts/vehicles/Vehicle.lua">
    	<specialization name="husbandryWater" />
        <specialization name="husbandryMilk" />
        <specialization name="husbandryStraw" />
        <specialization name="husbandryLiquidManure" />
        <specialization name="manureHeap" />
        <specialization name="FS22_ExpandablePastures.placeableHusbandryAnimalsExtension" />
    </type>
</placeableTypes>



Wenn man Gebäude oder Karten hat, die vor Expandable Pastures geladen werden, werden folgende beide Scripte benötigt. Diese können in der ModDesc eintragen werden. Beispielsweise (Danke an [EAM] GlengarBoy für die Scripte):

<extraSourceFiles>
	<sourceFile filename="scripts/expandablePastures_register.lua"/>
</extraSourceFiles>

<type name="cowHusbandryManure" parent="cowHusbandry" filename="$dataS/scripts/placeables/Placeable.lua">
            <specialization name="manureHeap" />
            <specialization name="expandablePasturesRegistry"/>
</type>

File expandablePastures_register.lua:

>>>
expandablePastures_register = {};

local modName = g_currentModName

-- add specializations to placeableTypes
function expandablePastures_register:register(name)

	-- make sure this only runs once since typeManager runce twice (vehicle and placeables)
    if expandablePastures_register.installed == nil then

		-- add/register specializations

		-- cycle placeableTypes, add specs
		local specCount = 0;
        for _, placeable in pairs(g_placeableTypeManager:getTypes()) do

			local placeableHusbandryExtension = false
			local expandablePasturesRegistry = false
			for _, spec in pairs(placeable.specializationNames) do
				if spec == "FS22_ExpandablePastures.placeableHusbandryAnimalsExtension" then
					placeableHusbandryExtension = true;
				end
				if spec == modName..".expandablePasturesRegistry" then
					expandablePasturesRegistry = true;
				end;
			end
			if not placeableHusbandryExtension and expandablePasturesRegistry then
				g_placeableTypeManager:addSpecialization(placeable.name, "FS22_ExpandablePastures.placeableHusbandryAnimalsExtension")
                specCount = specCount + 1;
			end

			expandablePastures_register.installed = true
		end
        print("Info: Successfully added FS22_ExpandablePastures.placeableHusbandryAnimalsExtension specialization to "..specCount .." placeableTypes in "..modName)
	end
end
TypeManager.finalizeTypes = Utils.prependedFunction(TypeManager.finalizeTypes, expandablePastures_register.register)

addModEventListener(expandablePastures_register)
<<<


File ExpandablePasturesRegistry.lua:

>>>
ExpandablePasturesRegistry = {}

function ExpandablePasturesRegistry.prerequisitesPresent(specializations)
    return true
end
<<<

